<?php
/**
 * @author: Gardennet
 * @date: 18-07-24
 * @email: lwp8800@sina.com
 */
namespace App\Services\Payment;

use App\Services\Payment\PayCore\wechat\WechatPayService;
use App\Services\Payment\PayCore\zhongxin\ZhongxinPayService;

class PaymentConfigService
{
    public $payment_config;

    public function setPaymentConfig($config = [])
    {
        $this->payment_config = $config;
    }

    public function getPaymentConfig()
    {
        return array_merge(config('payment'),$this->payment_config);
    }

    /**
     * 获取参数值
     *
     * @param $key
     * @return string
     */
    public function getParameter($key) {
        return isset($this->payment_config[$key])?$this->payment_config[$key] : '';
    }

    /**
     * 设置参数值
     *
     * @param $key
     * @param $value
     */
    public function setParameter($key, $value) {
        $this->payment_config[$key] = $value;
    }

    /**
     * 获取支付配置 默认使用微信支付
     * @param string type 支付方式   wechatPay:微信支付 zhongxinPay:中信支付
     * @return WechatPayService
     * @throws \Exception
     */
    public function getPaymentObject($type = 'wechatPay')
    {
        $config = $this->getPaymentConfig();
        switch ($type){
            case 'wechatPay':
                $object = new WechatPayService($config[$type]);
                break;
            case 'zhongxinPay':
                $object = new ZhongxinPayService($config[$type]);
                break;
            default:
                $object = new WechatPayService($config['wechatPay']);
        }
        return $object;
    }
}